home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / iritsm3s.zip / PROGRAM.H < prev    next >
C/C++ Source or Header  |  1992-01-26  |  13KB  |  287 lines

  1. /*****************************************************************************
  2. *   "Irit" - the 3d polygonal solid modeller.                     *
  3. *                                         *
  4. * Written by:  Gershon Elber                Ver 0.2, Mar. 1990   *
  5. ******************************************************************************
  6. * Main definition Header file  for Irit - the 3d polygonal solid modeller.   *
  7. *****************************************************************************/
  8.  
  9. #ifndef    IRIT_H
  10. #define    IRIT_H
  11.  
  12. #include <setjmp.h>    /* Used for the long jumps - to main iteration loop. */
  13. #include "irit_sm.h"
  14. #include "cagd_lib.h"       /* We define curves and surfaces handles as well. */
  15.  
  16. #ifdef __MSDOS__
  17. #define MAX_OBJ_LIST    50       /* Maximum size of geometric object list. */
  18. #else
  19. #define MAX_OBJ_LIST    250
  20. #endif /* __MSDOS__ */
  21.  
  22. #define DEFAULT_LOAD_COLOR 1  /* Default colors for object loaded using LOAD */
  23. #define DEFAULT_BOOL_COLOR 2  /* command, for boolean result objects, for    */
  24. #define DEFAULT_ICRV_COLOR 14 /* boolean intersection curves and for basic   */
  25. #define DEFAULT_PRIM_COLOR 4  /* primitives colors, respectively.         */
  26.  
  27. /* Objects (ObjectStruct - OBJECT_TYPE) types.                     */
  28. /* Dont change the order of these objects as the over loading table (see     */
  29. /* OverLoad.c) is hardwired to it. If you add objects update that module     */
  30. /* properly.                                     */
  31. typedef enum {
  32.     UNDEF_OBJ = 0,
  33.  
  34.     POLY_OBJ,
  35.     NUMERIC_OBJ,
  36.     VECTOR_OBJ,
  37.     MATRIX_OBJ,
  38.     CURVE_OBJ,
  39.     SURFACE_OBJ,
  40.     STRING_OBJ,
  41.     OBJ_LIST_OBJ,
  42.     CTLPT_OBJ,
  43.  
  44.     ANY_OBJ = 100         /* Match any object type, in type checking. */
  45. } IritObjectType;
  46.  
  47. #define NUM_OF_OBJECT_TYPES    8
  48.  
  49. #define DEFAULT_RESOLUTION    20    /* Used in Primitiv/Boolean modules. */
  50. #define DEFAULT_DRAW_CTLPT    FALSE    /* If control mesh/poly to be drawn. */
  51. #define DEFAULT_INTERNAL    FALSE          /* View of Internal edges? */
  52. #define DEFAULT_INTERCRV    FALSE          /* Return intersection curves? */
  53. #define DEFAULT_ECHOSRC        TRUE                /* Echo sourced program? */
  54. #define DEFAULT_DUMPLVL        0   /* Min. information. 1,2 are also valid. */
  55.  
  56. #define MACHINE_MSDOS        1
  57. #define MACHINE_SGI        2
  58. #define MACHINE_HP        3
  59. #define MACHINE_APOLLO        4
  60. #define MACHINE_SUN        5
  61. #define MACHINE_UNIX        6
  62.  
  63. #define KV_MIN_LEGAL        -9999
  64. #define KV_UNIFORM_OPEN        -10000
  65. #define KV_UNIFORM_FLOAT    -10001
  66.  
  67. #define MAX_NUM_ATTRS        10
  68.  
  69. /*****************************************************************************
  70. * Attributes - geometry types (Surfaces/Curves/Polygons/Polylines) have this *
  71. * structure for keeping general attributes like colors etc.             *
  72. *****************************************************************************/
  73. typedef struct AttributeStruct {
  74.     ByteType Color;                       /* Color of geometry. */
  75.     int NumStrAttribs;
  76.     char *StrAttrName[MAX_NUM_ATTRS + 1];        /* Generic string attrs. */
  77.     char *StrAttrData[MAX_NUM_ATTRS + 1];
  78. } AttributeStruct;
  79.  
  80. /*****************************************************************************
  81. * Global data structures:                             *
  82. * Objects in the system might be (real) scalars, (R3) vectors, matrices      *
  83. * (4 by 4 - transformation matrix), strings of chars, lists of objects, or   *
  84. * geometric objects. All but the last are simple and all their data is saved *
  85. * in the object space itself. The last (geometric) object points on a         *
  86. * polygonal list of the form:                             *
  87. *                                         *
  88. * Polygon -> Polygon -> Polygon -> Polygon -> .... -> NULL             *
  89. *    |        |       |          |                         *
  90. *    V          V          V          V                         *
  91. *  VList      VList      VList      VList    (VList = Vertex List)         *
  92. *                                         *
  93. * Each VList is a CIRCULAR vertex list. Each VList element (VertexStruct)    *
  94. * implicitly defines an edge from this vertex, to the next. As each edge     *
  95. * is used by exactly two polygons, a pointer to the other polygon using this *
  96. * edge exists in the VertexStruct. Each polygon has also its Plane         *
  97. * definition for fast processing, with its normal pointing INTO the object.  *
  98. *   Few other tags & flags are included in the data structures for different *
  99. * modules.                                     *
  100. *   Note, vertices are not shared by few VLists/Polygons although it may     *
  101. * decrease memory usage (suprisingly, not much). The main reason to that is  *
  102. * the basic assumption of this solid modeller, which is simplicity...         *
  103. *****************************************************************************/
  104.  
  105. /*****************************************************************************
  106. * Vertex Type - holds single 3D point, including some attributes on it as    *
  107. * Tags & Count. The 3D coordinates are saved in Pt. Pointer to next in chain *
  108. * is Pnext, and the pointer to the adjacent polygon (to the edge defined by  *
  109. * this Vertex and Vertex->Pnext) is PAdj.                     *
  110. *****************************************************************************/
  111. typedef struct VertexStruct {
  112.     ByteType Count, Tags;                 /* Same attributes. */
  113.     PointType Pt;                   /* Holds X, Y, Z coordinates. */
  114.     NormalType Normal;               /* Hold Vertex normal into the solid. */
  115.     struct PolygonStruct *PAdj;                 /* To adjacent polygon. */
  116.     struct VertexStruct *Pnext;                    /* To next in chain. */
  117. } VertexStruct;
  118.  
  119. /* Internal edge, or edge generated by the polygon decomposition stage when  */
  120. /* only convex polygons are allowed. This edge was not in the input         */
  121. /* non-convex polygon, and therefore one may not want to see/display it.     */
  122. /* Note bits 4-7 (high nibble of Tags) are reserved for the different         */
  123. /* modules to perform their local tasks and so should not be used here.         */
  124. #define INTERNAL_TAG    0x01           /* Edge Tag - This edge is internal.  */
  125.  
  126. #define    IS_INTERNAL_EDGE(Vrtx)    ((Vrtx)->Tags & INTERNAL_TAG)
  127. #define    SET_INTERNAL_EDGE(Vrtx)    ((Vrtx)->Tags |= INTERNAL_TAG)
  128. #define    RST_INTERNAL_EDGE(Vrtx)    ((Vrtx)->Tags &= ~INTERNAL_TAG)
  129.  
  130. /*****************************************************************************
  131. * Polygon Type - holds single polygon - Its Plane definition, and a pointer  *
  132. * to its vertices contour list V. As for VertexStruct, different attributes  *
  133. * can be saved in Count & Tags. PAux can be used locally by different         *
  134. * modules, for local usage only, and nothing sould be assumed on entry.         *
  135. *****************************************************************************/
  136. typedef struct PolygonStruct {
  137.     ByteType Count, Tags;                     /* Same attributes. */
  138.     PlaneType Plane;             /* Holds Plane as Ax + By + Cz + D. */
  139.     VoidPtr PAux;      /* May be used locally (temporary!) by any module. */
  140.     VertexStruct *V;                   /* To vertices circular list. */
  141.     struct PolygonStruct *Pnext;                /* To next in chain. */
  142. } PolygonStruct;
  143.  
  144. /* Note bits 4-7 (high nibble of Tags) are reserved for the different         */
  145. /* modules to perform their local tasks and so should not be used here.         */
  146. #define CONVEX_TAG    0x01      /* Convex Tag - Set if polygon is convex.  */
  147.  
  148. #define    IS_CONVEX_POLY(Poly)    ((Poly)->Tags & CONVEX_TAG)
  149. #define    SET_CONVEX_POLY(Poly)    ((Poly)->Tags |= CONVEX_TAG)
  150. #define    RST_CONVEX_POLY(Poly)    ((Poly)->Tags &= ~CONVEX_TAG)
  151.  
  152. typedef struct PolyListStruct {
  153.     AttributeStruct Attr;
  154.     struct PolygonStruct *P;
  155.     int IsPolyline;                 /* TRUE if polylines, FALSE if polygons */
  156. } PolyListStruct;
  157.  
  158. #define    IS_POLYLINE_OBJ(Obj)        ((int) (Obj->U.Pl.IsPolyline))
  159. #define    SET_POLYLINE_OBJ(Obj)        (Obj->U.Pl.IsPolyline = TRUE)
  160. #define    RST_POLYLINE_OBJ(Obj)        (Obj->U.Pl.IsPolyline = FALSE)
  161.  
  162. /*****************************************************************************
  163. * Free form curves and surfaces. Follow dthe cagd lib data structure with    *
  164. * some IRIT internal information.                         *
  165. *****************************************************************************/
  166. typedef struct CurveStruct {
  167.     AttributeStruct Attr;
  168.     CagdCrvStruct *Crv;
  169.     CagdPolylineStruct *PLPolys; /* Piecewise linear polyline approx. curve. */
  170.     CagdPolylineStruct *CtlPoly;             /* Control Polygon. */
  171. } CurveStruct;
  172.  
  173. typedef struct SurfaceStruct {
  174.     AttributeStruct Attr;
  175.     CagdSrfStruct *Srf;
  176.     CagdPolylineStruct *PLPolys;  /* Piecewise linear polylines approx. srf. */
  177.     CagdPolylineStruct *CtlMesh;                /* Control Mesh. */
  178.     struct ObjectStruct *Polygons; /* If srf has been converted to polygons. */
  179. } SurfaceStruct;
  180.  
  181. /*****************************************************************************
  182. * Object Type - main system structure, which holds all the objects defined   *
  183. * in the system like Numeric, Geometric etc.                     *
  184. *   Note that as the number of objects will be usually extermely low (100 is *
  185. * high estimate!) we can waste some memory here...                 *
  186. *****************************************************************************/
  187. typedef struct ObjectStruct {
  188.     char Name[OBJ_NAME_LEN];                  /* Name of object. */
  189.     IritObjectType ObjType;        /* Object Type: Numeric, Geometric, etc. */
  190.     ByteType Count;           /* Count Number of references to this object. */
  191.     union {
  192.     AttributeStruct Attr;             /* Pl/Crv/Srf has it as first slot. */
  193.     PolyListStruct Pl;                          /* Polygon/line list. */
  194.     CurveStruct Crv;                  /* Free form curve(s). */
  195.     SurfaceStruct Srf;                /* Free form surface(s). */
  196.     RealType R;                       /* Numeric real data. */
  197.     VectorType Vec;                    /* Numeric real vector data. */
  198.     CagdCtlPtStruct CtlPt;                  /* Control point data. */
  199.     MatrixType Mat;            /* Numeric 4 by 4 transformation matrix. */
  200.     struct ObjectStruct *PObjList[MAX_OBJ_LIST];     /* List of objects. */
  201.     char Str[LINE_LEN];          /* General string for text object. */
  202.     } U;
  203.     struct ObjectStruct *Pnext;                    /* To next in chain. */
  204. } ObjectStruct;
  205.  
  206. #define IS_UNDEF_OBJ(Obj)    ((Obj)->ObjType == UNDEF_OBJ)
  207. #define IS_POLY_OBJ(Obj)    ((Obj)->ObjType == POLY_OBJ)
  208. #define IS_NUM_OBJ(Obj)        ((Obj)->ObjType == NUMERIC_OBJ)
  209. #define IS_VEC_OBJ(Obj)        ((Obj)->ObjType == VECTOR_OBJ)
  210. #define IS_CTLPT_OBJ(Obj)    ((Obj)->ObjType == CTLPT_OBJ)
  211. #define IS_MAT_OBJ(Obj)        ((Obj)->ObjType == MATRIX_OBJ)
  212. #define IS_STR_OBJ(Obj)        ((Obj)->ObjType == STRING_OBJ)
  213. #define IS_OLST_OBJ(Obj)    ((Obj)->ObjType == OBJ_LIST_OBJ)
  214. #define IS_CRV_OBJ(Obj)        ((Obj)->ObjType == CURVE_OBJ)
  215. #define IS_SRF_OBJ(Obj)        ((Obj)->ObjType == SURFACE_OBJ)
  216.  
  217. #define IS_GEOM_OBJ(Obj)    (IS_UNDEF_OBJ(Obj) || \
  218.                  (Obj)->ObjType == POLY_OBJ || \
  219.                  (Obj)->ObjType == CURVE_OBJ || \
  220.                  (Obj)->ObjType == SURFACE_OBJ)
  221.  
  222. extern ObjectStruct
  223.     *GlblObjList;                   /* All objects on system. */
  224.  
  225. extern jmp_buf
  226.     GlblLongJumpBuffer;                      /* Used in error recovery. */
  227.  
  228. extern FILE
  229.     *GlblLogFile;           /* If do log everything, it goes to here. */
  230.  
  231. extern int
  232. #ifdef __MSDOS__             /* Defaults for MSDOS intr_lib windows. */
  233.     GlblWindowFrameWidth,
  234.     GlblViewFrameColor,
  235.     GlblViewBackColor,
  236.     GlblTransFrameColor,
  237.     GlblTransBackColor,
  238.     GlblStatusFrameColor,
  239.     GlblStatusBackColor,
  240.     GlblInputFrameColor,
  241.     GlblInputBackColor,
  242.     GlblDrawHeader,
  243.     GlblSmoothTextScroll,
  244.     GlblIntrSaveMethod,
  245.     GlblMouseSensitivity,         /* Sensitivity control of mouse device. */
  246.     GlblJoystickExists,
  247. #endif /*__MSDOS__ */
  248.     GlblMouseExists,
  249.     GlblFatalError,          /* True if disaster in system - must quit! */
  250.     GlblPrintLogFile,             /* If TRUE everything goes to log file. */
  251.     GlblDoGraphics,        /* Control if running in graphics/text mode. */
  252.     GlblLoadColor,          /* Default colors for object loaded using LOAD */
  253.     GlblBoolColor,          /* command, for boolean result objects or      */
  254.     GlblICrvColor,          /* boolean intersection curves and for basic   */
  255.     GlblPrimColor,           /* primitives colors, respectively.         */
  256.     GlblTransformMode,              /* Screen, Object coords. trans. mode. */
  257.     GlblViewMode,                   /* Perspective, Orthographic etc. */
  258.     GlblDrawSolid,             /* Use hardware Z buffer rendering. */
  259.     GlblDepthCue;                   /* Activate depth cueing. */
  260.  
  261. extern char 
  262. #ifdef __MSDOS__             /* Defaults for MSDOS intr_lib windows. */
  263.     *GlblViewWndwPos,
  264.     *GlblTransWndwPos,
  265.     *GlblStatusWndwPos,
  266.     *GlblInputWndwPos,
  267.     *GlblIntrSaveDisk,
  268. #endif /*__MSDOS__ */
  269. #ifdef __GL__
  270.     *GlblTransPrefPos,
  271.     *GlblViewPrefPos,
  272. #endif /* __GL__ */
  273.     *GlblHelpFileName,
  274.     *GlblStartFileName,            /* Name of startup file to executed. */
  275.     *GlblLogFileName,                    /* Name of log file. */
  276.     *GlblEditPrgm;        /* Name of editor to execute (edit command). */
  277.  
  278. void MyExit(int ExitCode);
  279. void FatalError(char * ErrorMsg);
  280. #ifdef __MSDOS__
  281. void cdecl DefaultFPEHandler(int Sig, int Type, int *RegList);
  282. #else
  283. void DefaultFPEHandler(int Type);
  284. #endif /* __MSDOS__ */
  285.  
  286. #endif    /* IRIT_H */
  287.